
//新建class星星
var starObj=function()
{
	this.x;
	this.y;
	this.picNo;
	this.timer;
	this.xSpd;
	this.ySpd;
	this.beat;
}

//  星星class初始化
starObj.prototype.init=function()
{
	this.x=Math.random()*600+100;
	this.y=Math.random()*300+150;	
	this.picNo=Math.floor(Math.random()*7);//使闪烁不同步，floor归一；
	this.timer=0;
	this.xSpd=Math.random()*3-1.5;
	this.ySpd=Math.random()*3-1.5;
}

//星星刷新
starObj.prototype.update=function()
{
	//星星移动
	this.x+=this.xSpd*deltaTime*0.005;
	this.y+=this.ySpd*deltaTime*0.005;
	//冲出边界初始化
	if(this.x<100||this.x>700)
	{
		this.init();
		return;
	}
	if(this.y<150||this.y>450)
	{
		this.init();
		return;
	}
	
	this.timer+=deltaTime;
	if(this.timer>50)
	{
		this.picNo+=1;
		this.picNo%=7
		this.timer=0;
	}
}

//星星绘画
starObj.prototype.draw=function()
{
	this.beat+=deltaTime*0.005;
	ctx.save();//与ctx.restore()一起使用，控制作用范围
	//星星 透明度
	ctx.globalAlpha=alive;
	//ctx.drawImage(img,sx.sy,sw,sh,x,y,w,h)
	ctx.drawImage(starPic,this.picNo*7,0,7,7,this.x,this.y,7,7);
	ctx.restore();
		
}



function drawStars()
{
	for(var i=0;i<num;i++)
	{
		stars[i].update();
		stars[i].draw();
		
	}	
}

function aliveUpdate()
{
	if(switchy){
		//show stars
		alive+=0.03*deltaTime*0.05;
		if(alive>1){alive=1;}
		}
	else{
		//hide
		alive-=0.03*deltaTime*0.05;
		if(alive<0){alive=0;}
		}	
}










